package org.wejde.muel;

import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

/**
 * This class contains the JComponents and functions
 * related to adding additional text to the event.
 * 
 * The JComponents in the class include the textArea, clear
 * button and submit button.
 * 
 * The methods include clearing the text area, retrieving
 * the text from the text area and passing the JButton
 * objects to other classes.
 * 
 * @author Eric Martin
 * @author Webb Pinner
 *
 */
public class additionalTextPane extends JPanel {

	/**
	 * The textArea for the additional text, thie object
	 * lives in a JScrollPane
	 */
	private JTextArea additionalText;
	
	/**
	 * The submit button
	 */
	private JButton submit;
	
	/**
	 * The clear button
	 */
	private JButton clear;
	
	/**
	 * The scroll pane for the textarea component.
	 */
	private JScrollPane additionalTextScroll;
	
	/**
	 * Serial Version UID
	 */
	private static final long serialVersionUID = 1241336055748829926L;

	/**
	 * Constructor method
	 */
	public additionalTextPane() {
		super(new FlowLayout(FlowLayout.LEFT));
		this.setMinimumSize(new Dimension(570,63));
		this.setSize(this.getMinimumSize());
		additionalText = new JTextArea(3,35);
		additionalText.setLineWrap(true);
		submit = new JButton("Submit");
		clear = new JButton("Clear");
		
		this.additionalTextScroll = new JScrollPane(additionalText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		this.add(additionalTextScroll);
		this.add(clear);
		this.add(submit);
	}
	
	/**
	 * Return the JButton object connected to the Submit
	 * button.
	 * 
	 * @return the submit JButton object.
	 */
	public JButton getSubmit() {
		return this.submit;
	}

	/**
	 * Return the JButton object connected to the Clear
	 * button.
	 * 
	 * @return the clear JButton object.
	 */
	public JButton getClear() {
		return this.clear;
	}
	
	/**
	 * Clear the contents of the additional textarea 
	 */
	public void clearFields() {
		this.additionalText.setText("");
		this.additionalText.setCaretPosition(0);
	}

	/**
	 * Return the contents of the additional textarea
	 * 
	 * @return contents of the additional text window.
	 */
	public String getAdditionalText() {
		return this.additionalText.getText().trim();
	}

}
